
import 'package:flutter/material.dart';

final Map<String, Map<String, Color>> colorMap = {
  'primary': {
    'color': Colors.white,
    'background': Colors.lightBlue
  },
  'success': {
    'color': Colors.white,
    'background': Colors.lightGreen
  },
  'info': {
    'color': Colors.white,
    'background': Colors.white54
  },
  'warning': {
    'color': Colors.white,
    'background': Colors.orange
  },
  'Danger': {
    'color': Colors.white,
    'background': Colors.redAccent
  },
};

class Button extends StatelessWidget {
  final VoidCallback? onClick;
  final String? type;
  final Widget child;
  final Color? color;
  final Color? background;

  late final Map<String, Color> allColor;

  _onPressed(){
    onClick!.call();
  }

  Button({super.key,  this.onClick, this.type, required this.child, this.color, this.background }) {
    final baseColors = colorMap[type] ?? {};

    allColor = {
      'color': color ?? baseColors['color'] ?? Colors.white,
      'background': background ?? baseColors['background'] ?? Colors.lightBlue,
    };

    debugPrint('background ---->>>> $allColor');
  }

  @override
  Widget build(BuildContext context) {
    return Expanded (
      child: ElevatedButton(
          style: ElevatedButton.styleFrom(
            backgroundColor: allColor['background'],
            foregroundColor: allColor['color'],
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(7)
            )
          ),
          onPressed: _onPressed,
          child: child
      ),
    );
  }

}
